package com.dreamwhale.accelerator.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.accelerator.common.DataResult;
import com.dreamwhale.accelerator.entity.AlUserFinancialRecords;
import com.dreamwhale.accelerator.mapper.AlUserFinancialRecordsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户收支记录表 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-08-07
 */
@RestController
@RequestMapping("/user")
public class AlUserFinancialRecordsController {

    @Resource
    private AlUserFinancialRecordsMapper alUserFinancialRecordsMapper;

    /**
     * 查询我的收支记录
     *
     * @param userId
     * @return
     */
    @RequestMapping("/selectAlUserRecordsByUserId")
    public DataResult selectAlUserRecordsByUserId(Integer page, Integer limit, Integer userId) {

        PageHelper.startPage(page, limit, true);
        QueryWrapper<AlUserFinancialRecords> queryWrapper = new QueryWrapper<AlUserFinancialRecords>();
        queryWrapper.eq("user_id", userId).orderByDesc("ufr_create_time");
        List<AlUserFinancialRecords> list = alUserFinancialRecordsMapper.selectList(queryWrapper);
        PageInfo<AlUserFinancialRecords> pages = new PageInfo<>(list);
        return DataResult.ok(pages);
    }

}

